export type KubeRouteItem = {
  name: string;
  path: string;
  component?: (() => any) | any;
};

export type KubeRouteGroup = {
  [key: string]: KubeRouteItem;
};

const kubeHudViews: Record<string, any> = import.meta.glob([
  "@/views/domain/kubeHud/views/manage/**/*.vue"
]);

console.log("kubeHudViews:", kubeHudViews);
const KRouteCluster: KubeRouteGroup = {
  Layout: {
    path: "/k8s/cluster",
    name: "ClusterRoot",
    component: "Layout"
  },

  List: {
    path: "/k8s/cluster/list",
    name: "ClusterList"
  },

  Details: {
    path: "/k8s/cluster/details",
    name: "ClusterDetails"
  }
};

const getComponent = (pathKey: string): any => {
  const path = `/src/views/domain/kubeHud/views/manage/${pathKey}.vue`;

  return kubeHudViews[path] ?? "Layout";
};

const KRouteNamespace: KubeRouteGroup = {
  List: {
    path: "/k8s/workload/namespace",
    name: "NamespaceList",
    component: getComponent("cluster/namespaces/index")
  },

  Create: {
    path: "/k8s/workload/namespace/create",
    name: "NamespaceCreate",
    component: getComponent("cluster/namespaces/create/index")
  },

  Details: {
    path: "/k8s/workload/namespace/details",
    name: "NamespaceDetails",
    component: getComponent("cluster/namespaces/detail/index")
  }
};

const KRouteNode: KubeRouteGroup = {
  List: {
    path: "/k8s/workload/node",
    name: "NodeList",
    component: getComponent("cluster/nodes/index")
  },

  Edit: {
    path: "/k8s/workload/node/edit",
    name: "NodeEdit",
    component: getComponent("cluster/nodes/edit/index")
  },

  Terminal: {
    path: "/k8s/workload/node/terminal",
    name: "NodeTerminal",
    component: getComponent("cluster/nodes/terminal/index")
  },

  Details: {
    path: "/k8s/workload/node/details",
    name: "NodeDetails",
    component: getComponent("cluster/nodes/detail/index")
  }
};

const KRouteWorkflow: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workflow",
    name: "WorkflowRoot"
  },

  List: {
    path: "/k8s/workflow/list",
    name: "WorkflowList"
  },

  Details: {
    path: "/k8s/workflow/details",
    name: "WorkflowDetails"
  }
};

const KRouteWorkload: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workload/layout",
    name: "WorkloadLayout"
  },

  List: {
    path: "/k8s/workload/list",
    name: "WorkloadList"
  },

  Details: {
    path: "/k8s/workload/details",
    name: "WorkloadDetails"
  }
};
const KRouteJob: KubeRouteGroup = {
  List: {
    path: "/k8s/workload/job",
    name: "JobList",
    component: getComponent("workloads/jobs/index")
  },

  Details: {
    path: "/k8s/workload/job/details",
    name: "JobDetails",
    component: getComponent("workloads/jobs/detail/index")
  }
};
const KRouteDeployment: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workload/deployment",
    name: "DeploymentLayout",
    component: "Layout"
  },

  List: {
    path: "/k8s/workload/deployment/list",
    name: "DeploymentList",
    component: getComponent("workloads/deployments/index")
  },

  Create: {
    path: "/k8s/workload/deployment/create",
    name: "DeploymentCreate",
    component: getComponent("workloads/index")
  },

  Edit: {
    path: "/k8s/workload/deployment/edit",
    name: "DeploymentEdit",
    component: getComponent("workloads/index")
  },

  Details: {
    path: "/k8s/workload/deployment/details",
    name: "DeploymentDetails",
    component: getComponent("workloads/deployments/detail/index")
  }
};
const KRoutePod: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workload/pod",
    name: "Pod",
    component: "Layout"
  },

  List: {
    path: "/k8s/workload/pod/list",
    name: "PodList",
    component: getComponent("workloads/pods/index")
  },

  Details: {
    path: "/k8s/workload/pod/details",
    name: "PodDetails",
    component: getComponent("workloads/pods/detail/index")
  },

  Create: {
    path: "/k8s/workload/pod/create",
    name: "PodCreate",
    component: getComponent("workloads/pods/create/index")
  },

  Edit: {
    path: "/k8s/workload/pod/edit",
    name: "PodEdit",
    component: getComponent("workloads/pods/edit/index")
  },

  Top: {
    path: "/k8s/workload/pod/top",
    name: "PodTop",
    component: getComponent("workloads/pods/top/index")
  }
};
const KRouteStatefulSet: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workload/statefulset",
    name: "StatefulSetList",
    component: "Layout"
  },

  List: {
    path: "/k8s/workload/statefulset",
    name: "StatefulSetList",
    component: getComponent("workloads/statefulsets/index")
  },

  Edit: {
    path: "/k8s/workload/statefulset/edit",
    name: "StatefulSetEdit",
    component: getComponent("workloads/index")
  },

  Create: {
    path: "/k8s/workload/statefulset/create",
    name: "StatefulSetCreate",
    component: getComponent("workloads/index")
  },

  Details: {
    path: "/k8s/workload/statefulset/details",
    name: "StatefulSetDetails",
    component: getComponent("workloads/statefulsets/detail/index")
  }
};
const KRouteDaemonSet: KubeRouteGroup = {
  Layout: {
    path: "/k8s/workload/daemonset",
    name: "DaemonSetList",
    component: "Layout"
  },

  List: {
    path: "/k8s/workload/daemonset",
    name: "DaemonSetList",
    component: getComponent("workloads/daemonsets/index")
  },

  Create: {
    path: "/k8s/workload/daemonset/create",
    name: "DaemonSetCreate",
    component: getComponent("workloads/index")
  },

  Edit: {
    path: "/k8s/workload/daemonset/edit",
    name: "DaemonSetEdit",
    component: getComponent("workloads/index")
  },

  Details: {
    path: "/k8s/workload/daemonset/details",
    name: "DaemonSetDetails",
    component: getComponent("workloads/daemonsets/detail/index")
  }
};

const KRouteLoadbalance: KubeRouteGroup = {
  Layout: {
    path: "/k8s/loadbalance",
    name: "LoadbalanceRoot"
  }
};

const KRouteService: KubeRouteGroup = {
  List: {
    path: "/k8s/loadbalance/service",
    name: "ServiceList",
    component: getComponent("network/services/index")
  },

  Details: {
    path: "/k8s/loadbalance/service/details",
    name: "ServiceDetails",
    component: getComponent("network/services/detail/index")
  },
  Create: {
    path: "/k8s/loadbalance/service/create",
    name: "ServiceCreate",
    component: getComponent("network/services/create/index")
  },
  Edit: {
    path: "/k8s/loadbalance/service/edit",
    name: "ServiceEdit",
    component: getComponent("network/services/edit/index")
  }
};

const KRouteIngress: KubeRouteGroup = {
  List: {
    path: "/k8s/loadbalance/ingress",
    name: "IngressList",
    component: getComponent("network/ingresses/index")
  },

  Details: {
    path: "/k8s/loadbalance/ingress/details",
    name: "IngressDetails",
    component: getComponent("network/ingresses/detail/index")
  },

  Create: {
    path: "/k8s/loadbalance/ingress/create",
    name: "IngressCreate",
    component: getComponent("network/ingresses/create/index")
  },

  Edit: {
    path: "/k8s/loadbalance/ingress/edit",
    name: "IngressEdit",
    component: getComponent("network/ingresses/edit/index")
  },

  Operate: {
    path: "/k8s/loadbalance/ingress/operate",
    name: "IngressOperate",
    component: getComponent("network/ingresses/operate/index")
  }
};

const KRouteStorage: KubeRouteGroup = {
  Layout: {
    path: "/k8s/storage",
    name: "StorageRoot",
    component: "Layout"
  }
};

const KRouteConfigMap: KubeRouteGroup = {
  Layout: {
    path: "/k8s/configuration/configmap",
    name: "ConfigMapList",
    component: "Layout"
  },

  List: {
    path: "/k8s/configuration/configmap",
    name: "ConfigMapList",
    component: getComponent("configuration/config-maps/index")
  },

  Details: {
    path: "/k8s/configuration/configmap/details",
    name: "ConfigMapDetails",
    component: getComponent("configuration/config-maps/detail/index")
  },

  Create: {
    path: "/k8s/configuration/configmap/create",
    name: "ConfigMapCreate",
    component: getComponent("configuration/config-maps/create/index")
  },

  CreateInYaml: {
    path: "/k8s/configuration/configmap/createInYaml",
    name: "ConfigMapCreateInYaml",
    component: getComponent("configuration/config-maps/create/index")
  },

  Edit: {
    path: "/k8s/configuration/configmap/edit",
    name: "ConfigMapEdit",
    component: getComponent("configuration/config-maps/edit/index")
  }
};

const KRouteSecret: KubeRouteGroup = {
  List: {
    path: "/k8s/configuration/secret",
    name: "SecretList",
    component: getComponent("configuration/secrets/index")
  },

  Create: {
    path: "/k8s/configuration/secret/create",
    name: "SecretCreate",
    component: getComponent("configuration/secrets/create/index")
  },

  Details: {
    path: "/k8s/configuration/secret/details",
    name: "SecretDetails",
    component: getComponent("configuration/secrets/detail/index")
  },

  Edit: {
    path: "/k8s/configuration/secret/edit",
    name: "SecretEdit",
    component: getComponent("configuration/secrets/edit/index")
  }
};

const KRoutePVC: KubeRouteGroup = {
  List: {
    path: "/k8s/storage/pvc",
    name: "PVCList",
    component: getComponent("storage/pvc/index")
  },

  Create: {
    path: "/k8s/storage/pvc/create",
    name: "PVCCreate",
    component: getComponent("storage/pvc/create/index")
  },

  Edit: {
    path: "/k8s/storage/pvc/edit",
    name: "PVCEdit",
    component: getComponent("storage/pvc/edit/index")
  },

  Details: {
    path: "/k8s/storage/pvc/details",
    name: "PVCDetails",
    component: getComponent("storage/pvc/detail/index")
  }
};

const KRoutePV: KubeRouteGroup = {
  List: {
    path: "/k8s/workload/pv",
    name: "PVList",
    component: getComponent("storage/pv/index")
  },

  Details: {
    path: "/k8s/workload/pv/details",
    name: "PVDetails",
    component: getComponent("storage/pv/detail/index")
  },
  Create: {
    path: "/k8s/workload/pv/create",
    name: "PVCreate",
    component: getComponent("storage/pv/create/index")
  }
};

const KRouteStorageClass: KubeRouteGroup = {
  List: {
    path: "/k8s/storage/storageclass",
    name: "StorageClassList",
    component: getComponent("storage/sc/index")
  },

  Create: {
    path: "/k8s/storage/storageclass/create",
    name: "StorageClassCreate",
    component: getComponent("storage/sc/create/index")
  },

  Details: {
    path: "/k8s/storage/storageclass/details",
    name: "StorageClassDetails",
    component: getComponent("storage/sc/detail/index")
  }
};

export {
  KRouteCluster,
  KRouteNamespace,
  KRouteNode,
  KRouteWorkflow,
  KRouteWorkload,
  KRouteJob,
  KRouteDeployment,
  KRoutePod,
  KRouteStatefulSet,
  KRouteDaemonSet,
  KRouteLoadbalance,
  KRouteService,
  KRouteIngress,
  KRouteStorage,
  KRouteConfigMap,
  KRouteSecret,
  KRoutePVC,
  KRoutePV,
  KRouteStorageClass
};
